package com.seocoo.worker.base.http;

import com.seocoo.worker.base.Const;
import com.seocoo.worker.base.entity.ELogin;
import com.sfh.lib.AppCacheManager;
import com.sfh.lib.http.transaction.IBuilderHeader;
import com.sfh.lib.http.transaction.OutreachRequest;

import okhttp3.Interceptor;
import okhttp3.logging.HttpLoggingInterceptor;

public class DWBaseRequest<T> extends OutreachRequest<T> {


    public DWBaseRequest(String path) {
        super(path);
    }

    @Override
    public String getUrl() {
        return Const.API;
    }


    @Override
    public void buildHeader(IBuilderHeader builder) {
        super.buildHeader(builder);
        ELogin login = AppCacheManager.getCacheListener().getObject(Const.LOGIN_KEY, ELogin.class);
        if (login != null) {
            builder.addHeader("token", login.getToken());
            builder.addHeader("Authorization", "Basic " + login.getToken());
        }
    }

    @Override
    public Interceptor getInterceptor() {
        HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
        //这行必须加 不然默认不打印
        interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
        return interceptor;
    }
}
